package com.wandian.news.mvvm.knowledge.historytoday;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.KnowledgeHistoryTodayRecycleAdapter;
import com.wandian.news.databinding.NewsActivityHistoryTodayBinding;
import com.wandian.news.databinding.NewsActivityKnowledgeBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 历史今天activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_HISTORY_TODAY)
public class HistoryTodayActivity extends BaseMVVMActivity<HistoryTodayActivityViewModel> {
    private NewsActivityHistoryTodayBinding dataBinding;
    private KnowledgeHistoryTodayRecycleAdapter adapter;
    @Override
    public void init(Bundle savedInstanceState) {

        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_history_today);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
        initRecycle();
        mViewModel.getData();
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("历史今天");

        mViewModel.dataBean.observe(this,dataBean->{
            if(!UIUtils.isEmpty(dataBean)){
                adapter.setNewData(dataBean);
            }
        });

    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> { finish(); });
    }

    private void initRecycle(){
        adapter = new KnowledgeHistoryTodayRecycleAdapter(R.layout.news_item_history_today);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        dataBinding.recycler.setLayoutManager(layoutManager);
        dataBinding.recycler.setAdapter(adapter);
    }

}
